
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>函数 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Landen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="变量提升.html" />
    
    
    <link rel="prev" href="bind&call&apply.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../01html/html简介.html">
            
                <a href="../01html/html简介.html">
            
                    
                    HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../01html/01html.html">
            
                <a href="../01html/01html.html">
            
                    
                    a链接、图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../01html/02html.html">
            
                <a href="../01html/02html.html">
            
                    
                    列表、表格、表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../01html/h5新增.html">
            
                <a href="../01html/h5新增.html">
            
                    
                    h5新增
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../02css/css简介.html">
            
                <a href="../02css/css简介.html">
            
                    
                    CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../02css/居中、省略、清浮.html">
            
                <a href="../02css/居中、省略、清浮.html">
            
                    
                    居中、省略、清浮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../02css/浮动和定位.html">
            
                <a href="../02css/浮动和定位.html">
            
                    
                    浮动和定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../02css/变换、过渡、动画.html">
            
                <a href="../02css/变换、过渡、动画.html">
            
                    
                    变换、过渡、动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../02css/sass和rem.html">
            
                <a href="../02css/sass和rem.html">
            
                    
                    sass和rem
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../02css/flex、media、栅格化.html">
            
                <a href="../02css/flex、media、栅格化.html">
            
                    
                    flex、media、栅格化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="js简介.html">
            
                <a href="js简介.html">
            
                    
                    JavaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="回流和重绘.html">
            
                <a href="回流和重绘.html">
            
                    
                    回流和重绘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="浏览器的渲染过程.html">
            
                <a href="浏览器的渲染过程.html">
            
                    
                    浏览器的渲染过程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="十大排序算法.html">
            
                <a href="十大排序算法.html">
            
                    
                    十大排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="对象的构建.html">
            
                <a href="对象的构建.html">
            
                    
                    对象的构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="bind&call&apply.html">
            
                <a href="bind&call&apply.html">
            
                    
                    bind&call&apply
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.10" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="变量提升.html">
            
                <a href="变量提升.html">
            
                    
                    变量提升
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="作用域.html">
            
                <a href="作用域.html">
            
                    
                    作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="存储.html">
            
                <a href="存储.html">
            
                    
                    存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="事件.html">
            
                <a href="事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="图片预览.html">
            
                <a href="图片预览.html">
            
                    
                    图片预览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="防抖节流.html">
            
                <a href="防抖节流.html">
            
                    
                    防抖节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="同步异步.html">
            
                <a href="同步异步.html">
            
                    
                    同步异步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="babel入门.html">
            
                <a href="babel入门.html">
            
                    
                    babel入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="nvm.html">
            
                <a href="nvm.html">
            
                    
                    nvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="ES6-ES11.html">
            
                <a href="ES6-ES11.html">
            
                    
                    ES6-ES11
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >函数</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x5B9A;&#x4E49;&#x51FD;&#x6570;">&#x5B9A;&#x4E49;&#x51FD;&#x6570;</h2>
<ol>
<li>&#x51FD;&#x6570;&#x58F0;&#x660E;&#x5F0F;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params"></span>)</span>{}
</code></pre>
<ol>
<li>&#x51FD;&#x6570;&#x8868;&#x8FBE;&#x5F0F;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> sum = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{}
</code></pre>
<h2 id="&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;">&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x9ED8;&#x8BA4;&#x53C2;&#x6570;</h2>
<ol>
<li><p>arguments</p>
</li>
<li><p>&#x63A5;&#x6536;&#x6240;&#x6709;&#x4F20;&#x9012;&#x8FC7;&#x6765;&#x7684;&#x5B9E;&#x53C2;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x4F2A;&#x6570;&#x7EC4;</p>
</li>
<li><p>this</p>
</li>
<li><p>&#x8868;&#x793A;&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#xFF0C;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;&#x6307;&#x5411;</p>
</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sum</span>(<span class="hljs-params">a, b</span>) </span>{
    <span class="hljs-comment">// &#x9A8C;&#x8BC1;&#x5982;&#x4E0B;&#xFF0C;&#x4FEE;&#x6539;arguments&#x5185;&#x5BB9;&#xFF0C;&#x5BFC;&#x81F4;&#x5F62;&#x53C2;a,b&#x53D8;&#x5316;</span>
    <span class="hljs-built_in">arguments</span>[<span class="hljs-number">0</span>] = <span class="hljs-number">100</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">arguments</span>[<span class="hljs-number">0</span>]);

    <span class="hljs-comment">// &#x4F5C;&#x4E3A;&#x51FD;&#x6570;&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x5185;&#x90E8;this&#x6307;&#x5411;&#x4E8E;window</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>);
    <span class="hljs-keyword">return</span> a + b;
}
<span class="hljs-built_in">console</span>.log(sum(<span class="hljs-number">5</span>, <span class="hljs-number">10</span>));
</code></pre>
<ul>
<li>&#x8865;&#x5145;&#xFF1A;&#x5904;&#x7406;&#x5269;&#x4F59;&#x53C2;&#x6570;&#xFF0C;rest &#x53C2;&#x6570;&#x7528;&#x4E8E;&#x63A5;&#x6536;&#x6240;&#x6709;&#x5269;&#x4F59;&#x53C2;&#x6570;&#xFF0C;&#x6CE8;&#x610F;&#x8981;&#x4F5C;&#x4E3A;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x5F62;&#x53C2;&#x4F7F;&#x7528;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn</span>(<span class="hljs-params">a, ...arg</span>) </span>{
    <span class="hljs-built_in">console</span>.log(a, arg);
}
fn(<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>, <span class="hljs-number">50</span>);
</code></pre>
<h2 id="&#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#x65B9;&#x5F0F;">&#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#x65B9;&#x5F0F;</h2>
<ol>
<li>&#x76F4;&#x63A5;&#x8C03;&#x7528;&#x51FD;&#x6570;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fn1</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;fn1&quot;</span>);
};
fn1();
</code></pre>
<ol>
<li>&#x4F5C;&#x4E3A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;/&#x65B9;&#x6CD5;&#x8C03;&#x7528;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> obj = {
    say: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x8BF4;&#x70B9;&#x4EC0;&#x4E48;&quot;</span>);
    }
};
obj.say();
</code></pre>
<ol>
<li>&#x4F7F;&#x7528; call applay &#x8C03;&#x7528;&#x51FD;&#x6570;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sayName</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// this:&#x51FD;&#x6570;&#x6267;&#x884C;&#x65F6;&#x6240;&#x5728;&#x7684;&#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">&quot;&#x6211;&#x53EB;:&quot;</span> + <span class="hljs-keyword">this</span>.name;
}
<span class="hljs-keyword">var</span> people = {
    name: <span class="hljs-string">&quot;melon&quot;</span>,
};
<span class="hljs-built_in">console</span>.log(people.sayName); <span class="hljs-comment">// undefined,&#x5BF9;&#x8C61;&#x8EAB;&#x4E0A;&#x6CA1;&#x6709;&#x5BF9;&#x5E94;&#x65B9;&#x6CD5;</span>
<span class="hljs-built_in">console</span>.log(sayName.call(people)); <span class="hljs-comment">// &#x6211;&#x53EB;:melon</span>
</code></pre>
<ol>
<li>&#x4F5C;&#x4E3A;&#x6784;&#x9020;&#x51FD;&#x6570;&#x8C03;&#x7528;</li>
</ol>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Cat</span>(<span class="hljs-params">color</span>)</span>{
    <span class="hljs-keyword">this</span>.color = color;
}
<span class="hljs-keyword">let</span> whiteCat = <span class="hljs-keyword">new</span> Cat(<span class="hljs-string">&quot;&#x767D;&#x8272;&quot;</span>);
<span class="hljs-built_in">console</span>.log(whiteCat);
</code></pre>

                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="bind&call&apply.html" class="navigation navigation-prev " aria-label="Previous page: bind&call&apply">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="变量提升.html" class="navigation navigation-next " aria-label="Next page: 变量提升">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"函数","level":"1.4.10","depth":2,"next":{"title":"变量提升","level":"1.4.11","depth":2,"path":"md/03js/变量提升.md","ref":"./md/03js/变量提升.md","articles":[]},"previous":{"title":"bind&call&apply","level":"1.4.9","depth":2,"path":"md/03js/bind&call&apply.md","ref":"./md/03js/bind&call&apply.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","toggle-chapters","image-captions","-anchor-navigation","-anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"image-captions":{"attributes":{"style":"left: 50%;position: relative;transform: translateX(-50%);"},"caption":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_","align":"center","variable_name":"_pictures"},"fontsettings":{"theme":"night","family":"sans","size":2},"toggle-chapters":{},"highlight":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Landen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[]},"gitbook":"3.x.x"},"file":{"path":"md/03js/函数.md","mtime":"2020-07-27T15:21:48.696Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T10:41:18.504Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

